package com.work.user.dao;

import com.work.user.pojo.Menu;
import com.work.user.pojo.Role;
import com.work.user.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface RoleMapper extends Mapper<Role> {

    //设置角色和权限一对多关系
    @Insert("insert into t_role_menu(rid,mid) values(#{rid},#{mid})")
    void setRoleAndMenu(Map map);

    //查询中间表 根据id查询用户所拥有的角色
    @Select("select r.* from t_role r, t_user_role ur where r.id = ur.rid and ur.uid = #{id}")
    public Set<Role> findByUserId(int id);

    //删除中间关系表
    @Delete("delete from t_role_menu where rid = #{id}")
    void deleteAssocication(Integer id);

    //添加用户
    @Insert("insert into t_role(role,info,category) value(#{role},#{info},#{category})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    void add(Role role);
}
